<script setup>
import Header from "@/components/Header.vue";
import {inject, provide, watch, ref} from "vue";
import {getUser} from "@/api/AuthApi.js";
import {getWallet} from "@/api/WalletApi.js";
import { useRouter } from 'vue-router'

const router = useRouter()
const isLogin = inject("isLogin");
const myUser = inject("myUser");
const myWallet = inject("myWallet");
const hasHeader = ref(true);

// 获取用户信息
getUser().then(res=>{
  if (res.code===1) {
    isLogin.value = true;
    for (let key in res.data) {
      myUser[key] = res.data[key];
    }
  }
}).catch(err=>{
});
// 查询用户钱包
getWallet().then(resp=>{
  if(resp.code === 1) {
    for (let key in resp.data) {
      myWallet[key] = resp.data[key];
    }
  }
}).catch(err=>{
});

watch(() => 
    router.currentRoute.value.path,
    (toPath) => {
      console.log(toPath);
      if(toPath.split('/')[1]==='manage') {
        hasHeader.value = false;
      } else {
        hasHeader.value = true;
      }
    },{immediate: true,deep: true}
)
</script>
<template>
  <Header v-if="hasHeader"></Header>
  <RouterView></RouterView>
</template>
<style scoped>
</style>
